package com.ludi.basics.advice;

import com.ludi.basics.pojo.vo.RespCodeType;
import com.ludi.basics.pojo.vo.RespResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author ludi
 * @date:2020/8/21 15:43
 * @description:全局异常处理器
 */
@ControllerAdvice
@RestControllerAdvice
public class ExceptionsHandler {
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public RespResult exceptionHandler(Exception e){
        RespResult respResult = new RespResult();
        respResult.setCode(RespCodeType.FAIL);
        respResult.setMessage(e.getMessage());
        return respResult;
    }
}
